cmake_minimum_required(VERSION 3.5)

project(qtwindow LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR OFF)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../bin/${CMAKE_BUILD_TYPE}/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../bin/${CMAKE_BUILD_TYPE}/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../bin/${CMAKE_BUILD_TYPE}/bin)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core Qml Xml Svg PrintSupport REQUIRED)

file(GLOB_RECURSE HEAD_FILES "*.h")
file(GLOB_RECURSE SRC_FILES "*.cpp")
file(GLOB_RECURSE UI_FILES "*.ui")
file(GLOB_RECURSE HPP_FILES "*.hpp")
file(GLOB_RECURSE C_FILES "*.c")
file(GLOB_RECURSE RES_FILES "*.qrc")
file(GLOB_RECURSE JS_FILES "*.js")

add_executable(qtwindow
    ${HEAD_FILES}
    ${SRC_FILES}
    ${UI_FILES}
    ${HPP_FILES}
    ${C_FILES}
    ${RES_FILES}
    ${JS_FILES}
    )

#add_subdirectory(CMakeFiles EXCLUDE_FROM_ALL)

target_link_libraries(qtwindow PRIVATE Qt5::Widgets)
target_link_libraries(qtwindow PRIVATE Qt5::Core Qt5::Qml Qt5::PrintSupport)
target_link_libraries(qtwindow PRIVATE Qt5::Xml)
target_link_libraries(qtwindow PRIVATE Qt5::Svg)

# 复制文件 构建前复制文件
add_custom_command(TARGET qtwindow POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
            ${CMAKE_CURRENT_SOURCE_DIR}/m.js
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/m.js)

# build_windeployqt.bat
add_custom_command(TARGET qtwindow POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
            ${CMAKE_CURRENT_SOURCE_DIR}/build_windeployqt.bat
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build_windeployqt.bat)

#if(WIN32)
#  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
#  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
#else()
#  add_compile_options(-finput-charset=UTF-8 -fexec-charset=UTF-8)
#endif()
if(WIN32)
    # 临时设置控制台代码页为UTF-8
    execute_process(COMMAND chcp 65001)
endif()
message("-----Path&Dir 路径与目录-----")
message("PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}")
message("PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
message("CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")
message("CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}")
message("CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}")
message("CMAKE_CURRRENT_BINARY_DIR = ${CMAKE_CURRRENT_BINARY_DIR}")
message("CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
message("CMAKE_CURRENT_LIST_FILE = ${CMAKE_CURRENT_LIST_FILE}")
message("CMAKE_CURRENT_LIST_LINE = ${CMAKE_CURRENT_LIST_LINE}")
message("EXECUTABLE_OUTPUT_PATH = ${EXECUTABLE_OUTPUT_PATH}")
message("LIBRARY_OUTPUT_PATH = ${LIBRARY_OUTPUT_PATH}")
message("-----Buid构建控制-----")
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message("BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}")
message("CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}")
message("CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
message("-----Compile&link编译与链接选项-----")
message("CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
message("CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message("CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message("CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}")
message("CMAKE_STATIC_LINKER_FLAGS = ${CMAKE_STATIC_LINKER_FLAGS}")
message("CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}")
message("-----System&Platform系统与平台信息-----")
message("CMAKE_SYSTEM = ${CMAKE_SYSTEM}")
message("CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
message("WIN32 = ${WIN32}")
message("UNIX = ${UNIX}")
message("APPLE = ${APPLE}")
message("MSVC = ${MSVC}")
message("CMAKE_SIZEOF_VOID_P = ${CMAKE_SIZEOF_VOID_P}")
message("-----Module&Find模块与查找路径-----")
message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
message("CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}")
message("CMAKE_INCLUDE_PATH = ${CMAKE_INCLUDE_PATH}")
message("CMAKE_LIBRARY_PATH = ${CMAKE_LIBRARY_PATH}")
message("-----Generator&Linker生成器与工具链-----")
message("CMAKE_GENERATOR = ${CMAKE_GENERATOR}")
message("CMAKE_MAKE_PROGRAM = ${CMAKE_MAKE_PROGRAM}")
message("-----Version版本信息-----")
message("CMAKE_VERSION = ${CMAKE_VERSION}")
message("CMAKE_SYSTEM_VERSION = ${CMAKE_SYSTEM_VERSION}")
message("CMAKE_SYSTEM_PROCESSOR   = ${CMAKE_SYSTEM_PROCESSOR}")
message("CMAKE_PROJECT_VERSION = ${CMAKE_PROJECT_VERSION}")
message("PROJECT_VERSION_MAJOR = ${PROJECT_VERSION_MAJOR}")
message("PROJECT_VERSION_MINOR = ${PROJECT_VERSION_MINOR}")
message("PROJECT_VERSION_PATCH = ${PROJECT_VERSION_PATCH}")
message("PROJECT_NAME = ${PROJECT_NAME}")
message("-----CrossComplite跨编译相关-----")
message("CMAKE_CROSSCOMPILING = ${CMAKE_CROSSCOMPILING}")
message("CMAKE_SYSROOT = ${CMAKE_SYSROOT}")
message("CMAKE_STAGING_PREFIX = ${CMAKE_STAGING_PREFIX}")
message("--------------------------------------------")
